VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsStatusEnquiry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
'Public Function CreateApproveFile(lngInterfaceNo As Long, Optional strFailReason As String) As Boolean
'
'    Dim strXmlHeader As String
'    Dim strXmlVersDtdHeader As String
'    Dim lngNewInterfaceNo As Long
'    Dim strNewMsgId As String
'    Dim strOraErr As String
'
'    ClearIdxVars
'
''    If Not ConnectToDb(strOraErr) Then
''        WriteToErr "Error connecting to database: " & strOraErr
''        Exit Function
''    End If
'
'    'barb: set these = nothing eventually
'    Set objFileError = New clsStatusEnquiry
'    Set objFunctions = New clsStatusFunctions
'    Set objReg = New clsReg
'    Set objSendEMail = New clsSendEMail
'
'    If objFunctions.ExtractIndexBlobFromDb(lngInterfaceNo) = True Then
'            If objFunctions.ValidateXmlFormat(strFailReason) Then
'                If objFunctions.GetHeaderData Then
'                    If objFunctions.ValidateHeaderData(strFailReason) Then
'                        strXmlHeader = objFunctions.CreateXmlHeader
'                        'produce error file
'                        strXmlVersDtdHeader = objFunctions.CreateXmlVersionDtdHeader
'                        'If objFunctions.CreateFileApproval(strXmlHeader, strXmlError) Then
'                            adoConn.BeginTrans
'                            If objFunctions.InsertIntoInterfaceIndex(lngNewInterfaceNo, strNewMsgId) Then
'                                If objFunctions.InsertIntoInterfaceXml(lngNewInterfaceNo, strNewMsgId, strXmlVersDtdHeader, strXmlHeader) Then
'                                    adoConn.CommitTrans
'                                    CreateApproveFile = True
'                                Else
'                                    adoConn.RollbackTrans
'                                    strFailReason = "InsertIntoInterfaceXml failed"
'                                    CreateApproveFile = False
'                                End If
'                            Else
'                                adoConn.RollbackTrans
'                                strFailReason = "InsertIntoInterfaceIndex failed"
'                                CreateApproveFile = False
'                            End If
'
'                    Else
'                        CreateApproveFile = False
'                    End If
'                Else
'                    strFailReason = "GetHeaderData failed"
'                    CreateApproveFile = False
'                End If
'            Else
'                strFailReason = "ValidateXmlFormat failed: " & strFailReason
'                CreateApproveFile = False
'            End If
'    Else
'        strFailReason = "ExtractIndexBlobFromDb failed"
'        CreateApproveFile = False
'    End If
'
'End Function

Public Function GetStatus(arParameters As Variant, Optional strFailReason As String) As Boolean

    'Variables
    Dim strSql As String
    Dim strOraErr As String
    Dim lngInterfaceNo As Long
    Dim strUserId As String
    Dim strEmailAdrr As String
    Dim rsIndex As ADODB.Recordset
    Dim lngReqSeqNum As String
    Dim objKtDll As Object

    On Error GoTo GetStatusFix

    lngInterfaceNo = CLng(arParameters(0))
    strUserId = arParameters(1)
    strEmailAdrr = arParameters(2)
    
    'initilize the recordset
    Set rsIndex = New ADODB.Recordset
    rsIndex.CursorType = adOpenKeyset
    rsIndex.LockType = adLockOptimistic

     If Not ConnectToDb(strOraErr) Then
        strFailReason = "Error connecting to database: " & strOraErr
        GetStatus = False
        Exit Function
    End If

    'barb: add data validation/call errordll

    'Get the ReqSeqNum from the db
    strSql = "Select REQ_SEQ_NUM from DIR_INTERFACE_INDEX where INTERFACE_NO =" & lngInterfaceNo
     Set rsIndex = adoConn.Execute(strSql)
    If rsIndex.RecordCount > 0 Then
        lngReqSeqNum = rsIndex!REQ_SEQ_NUM
        strSql = "Select REQ_SEQ_NUM from DIR_REQUEST where REQ_SEQ_NUM =" & lngReqSeqNum
        Set rsIndex = adoConn.Execute(strSql)
        If rsIndex.RecordCount > 0 Then
                Set objKtDll = CreateObject("KeyTax.clsRequests")
                IdxVars.Tracking.NewRequestStatus = objKtDll.GetRequestStatus(lngReqSeqNum)
                Set objKtDll = Nothing
                If Len(Trim(IdxVars.Tracking.NewRequestStatus)) = 0 Then
                    strFailReason = "Approved ReqSeqNum: " & lngReqSeqNum & " not found in DIR_RESPONSE (This is not an approved directive). Interface no: " & lngInterfaceNo
                    GetStatus = False
                Else
                    Dim dllCreateApproveFile As Object
                    Set dllCreateApproveFile = CreateObject("FileApprove.clsFileApprove")
                    If dllCreateApproveFile.CreateApproveFile(lngInterfaceNo, strFailReason) Then
                        GetStatus = True
                    Else
                        GetStatus = False
                    End If
                End If
        Else
            strFailReason = "Approved ReqSeqNum: " & lngReqSeqNum & " not found in DIR_RESPONSE (This is not an approved directive). Interface no: " & lngInterfaceNo
            GetStatus = False
        End If
    Else
        strFailReason = "InterfaceNo: " & lngInterfaceNo & " not found in DIR_INTERFACE_INDEX. "
        GetStatus = False
    End If
    
   Exit Function
   
'clean up
Set dllCreateApproveFile = Nothing
   
GetStatusFix:
    GetStatus = False
    strFailReason = "GetStatus: " & Err.Number & " - " & Err.Description
End Function

'Private Function MarkAsCancelled(ReqSeqNum As String, Optional strFailReason As String) As Boolean
'
'    Dim strSql As String
'    Dim rsIndex As ADODB.Recordset
'
'    On Error GoTo MarkAsCancelledFix
'
'    'initilize the recordset
'    Set rsIndex = New ADODB.Recordset
'    rsIndex.CursorType = adOpenKeyset
'    rsIndex.LockType = adLockOptimistic
'
'
'
'    Exit Function
'
'MarkAsCancelledFix:
'    strFailReason = "MarkAsCancelled: " & Err.Number & " - " & Err.Description
'    MarkAsCancelled = False
'End Function




    

'Public Function GetHeaderFromText() As String
'
'    Dim strTemp1 As String
'    Dim strTemp2 As String
'    Dim lPos As Long
'    Dim strTypeOfRequest As String
'
'    On Error GoTo GetHeaderFromTextFix
'
'    lPos = InStr(1, IdxVars.XmlString, "</Tracking>")
'    If lPos <> 0 Then
'        'get text up til end of header then close root node
'        strTemp1 = Mid(IdxVars.XmlString, 1, lPos + 11)
'        'remove version & dtd line
'        lPos = InStr(1, strTemp1, ".dtd") + 8
'        If lPos > 0 Then
'            strTemp2 = Mid(strTemp1, lPos, Len(strTemp1) - lPos)
'        End If
'        'change KeyTax Type to "10" for error
'        lPos = InStr(1, strTemp2, "<KeyTax Type=") + 13
'        If lPos > 0 Then
'            Select Case IdxVars.KeyTaxType
'                Case "01", "03", "07", "08"
'                Case Else
'                    IdxVars.KeyTaxType = Mid(strTemp2, lPos + 1, 2)
'            End Select
'            strTemp1 = Mid(strTemp2, 1, lPos) & "" & "10" & """"
'            strTemp1 = strTemp1 & Mid(strTemp2, lPos + 4, Len(strTemp2))
'        End If
'        'change the Request Status to "15" for error
'        lPos = InStr(1, strTemp1, "<RequestStatus Type=") + 20
'        If lPos > 0 Then
'            strTemp2 = Mid(strTemp1, 1, lPos) & "" & "15" & """"
'            strTemp2 = strTemp2 & Mid(strTemp1, lPos + 4, Len(strTemp1))
'        End If
'
'        strTemp2 = strTemp2 & "</KeyTax>"
'
'
'        GetHeaderFromText = strTemp2
'    Else
'        GetHeaderFromText = ""
'    End If
'
'    Exit Function
'
'GetHeaderFromTextFix:
'    MsgBox "GetHeaderFromText: " & Err.Number & " - " & Err.Description
'End Function
'********************************************************************************************************
Private Sub ClearIdxVars()

    'barb: start here
    'validation + "" and "NULL"
    'clean up
    'johan to write to created_date
    'sort out dtd location
    'remove all apostrophes from database data before inserting/updating

    IdxVars.InterfaceNo = 0
    IdxVars.XmlString = ""
    IdxVars.CreatedDated = ""
    IdxVars.SarsResponseYn = ""
    IdxVars.KeyTaxType = ""
    IdxVars.MqStatus = ""

    'Tracking Vars
    IdxVars.Tracking.MsgId = ""
    IdxVars.Tracking.ComId = ""
    IdxVars.Tracking.BuId = ""
    IdxVars.Tracking.ReferenceId = ""
    IdxVars.Tracking.ReqSeqNum = ""
    IdxVars.Tracking.RequestStatus = ""

    'Requestor Vars
    IdxVars.Request.Date = ""
    IdxVars.Request.Email = ""
    IdxVars.Request.Name = ""
    IdxVars.Request.Time = ""
    IdxVars.Request.UserId = ""

End Sub
